package com.blb.topic;

import com.blb.util.MQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 主题模式的生产者
 */
public class TopicProductor {

    public static void main(String[] args) throws IOException, InterruptedException {
        Connection connection = MQUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机类型为topic
        channel.exchangeDeclare(MQUtils.EXCHANGE_NAME3,"topic");
        //绑定队列到交换机，最后指定了Key
        channel.queueBind(MQUtils.QUEUE_NAME,MQUtils.EXCHANGE_NAME3,"xray.#");
        //绑定队列到交换机，最后指定了Key
        channel.queueBind(MQUtils.QUEUE_NAME2,MQUtils.EXCHANGE_NAME3,"*.*.cn");
        String msg = "Hello-->Topic123456";
        channel.basicPublish(MQUtils.EXCHANGE_NAME3,"xray.com.cn",null,msg.getBytes());
        System.out.println("send:" + msg);
        channel.close();
        connection.close();
    }
}
